/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package assignment_cp3120.manager.deleteairport;

import assignment_cp3120.DAO.Factory.DAOFactory;
import assignment_cp3120.dataObjects.DepartureLocation;
import assignment_cp3120.ucm.UC2AL;
import assignment_cp3120.ucm.UCDeleteAirport;
import java.awt.FlowLayout;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JPanel;

/**
 *
 * @author Administrator
 */
public class DeleteAirportView extends JPanel {
    private DeleteAirportModel model;
    
    private JButton deleteButton;
    private JComboBox deleteAirportChoiceCBox;

    public DeleteAirportView(DeleteAirportModel model) {
        this.model = model;

        createView();
    }    
    public DeleteAirportView() {
        this(new DeleteAirportModel());
    }
    public DepartureLocation getSelectedAirport() {
        System.out.println(deleteAirportChoiceCBox.getSelectedIndex());
        return model.getAirports().get(deleteAirportChoiceCBox.getSelectedIndex());
    }
    private void createView() {
        deleteButton = new JButton("Delete");
        deleteButton.addActionListener(new UC2AL(new UCDeleteAirport(this, model)));

        deleteAirportChoiceCBox = new JComboBox(model.getAirports());
        JPanel deletePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        //setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
        deletePanel.add(deleteAirportChoiceCBox);

        add(deletePanel);
        add(deleteButton);
    }
    public void clearView() {
        model.loadAirports();
        this.removeAll();
        createView();
        this.validate();
    }
}
